
//----Acan.login
Acan.login = function(obj){	return Acan.login.anew(obj);}
Acan.login.anew = function(obj){this.obj=obj;	return this;}
Acan.login.reg_save = function(){
	var msgok = '<span class="-green">ok</span>';
var exp = {username:/([a-zA-Z0-9]{5,10})/,mail:Acan.regexp.mail,info_qq:Acan.regexp.qq};
	var Dbj = jQuery('.user_reg form');
	var regrr = Dbj.serializeArray();
	var data = Dbj.serialize();
	for(var i in regrr){
		var name = regrr[i].name.replace('][','_').replace('save[','').replace(']','');
		if(Dbj.find('.msg_'+name).length==0){
			Dbj.find('input[name="'+regrr[i].name+'"]').after('<span class="msg_'+name+'"></span>');
		}
		if(exp[name] && !exp[name].test(regrr[i].value)){
			Dbj.find('.msg_'+name).html('<span class="-red">格式错误</span>');
			Dbj.find('input[name="'+regrr[i].name+'"]').focus();
			return false;
		}else{
			Dbj.find('.msg_'+name).html(msgok);
		}
	}
	var pbj = Dbj.find('input[name="save[password]"]');
	var pbjm = Dbj.find('.msg_password');
	if(pbj.val().length<6 || pbj.val().length>18){
		pbjm.html('<span class="-red">格式错误</span>');pbj.focus();
		return false;
	}else{
		pbjm.html(msgok)
	}
	var pbj2 = Dbj.find('input[name="save[password2]"]');
	var pbj2m = Dbj.find('.msg_password2');
	if(pbj.val()!=pbj2.val()){
		pbj2m.html('<span class="-red">两次密码不一样</span>');pbj2.focus();
		return false;
	}else{
		pbj2m.html(msgok)
	}
	jQuery.ajax({
		type: "GET",
		url: '/'+Aurl.App+'-user-reg_rand',
		data:{username:Dbj.find('input[name="save[username]"]').val()},
		success: function(rand){
			jQuery.ajax({
				type: "POST",
				url: '/'+Aurl.App+'-user-reg_go?rand='+rand,
				data:data,
				success: function(data){
					if(data.status==0){
						jQuery('input[name="save['+data.code+']"]').focus();
						Dbj.find('.msg_'+data.code).html('<span class="-red">'+data.msg+'</span>');
					}else{
						Acan.alert(data.msg);
					}
				}
			});
		}
	});
	return false;
}
//--检查顶部登入状态
Acan.login.refresh = function(data){
	if(data){
		if(!jQuery("#acan_login").attr('id')){setTimeout("Acan.url.refresh()",1000);return;}
		else{}
	}else{
		var data = Acan.base.json_obj(Acan.cookie.get("acan_user"));
	}
	var html = "";
	if(typeof(data)=='object'){
		if(data.usergroup=='1'){
			html += '<a href="/admin.php">后台管理</a> ';
			html += '<a href="/asys.php">系统管理</a> ';
		}
		html += '<a href="index.php">'+data.username+'</a> ';
		html += '<a href="/center">用户中心</a> ';
		html += '<a href="/mall/cart">购物车</a> ';
		html += '<a onclick="Acan.login.logout()">退出</a>';
	}else{
		html = '<a onclick="Acan.login.show()">登入</a> | <a onclick="Acan.login.reg()">注册</a> | <a href="https://www.alipay.com/cooperate/gateway.do?_input_charset=utf-8&partner=2088002126244997&return_url=http://www.abans.cn/api/alipay/return_login.php&service=user_authentication&sign=3aeee94c81ad9486424845a020322e0b&sign_type=MD5">支付宝账户登录</a> <a target="_blank" href="http://qun.qq.com/#jointhegroup/gid/49642170">加入Acan</a>';
	}
	jQuery("#acan_login").html(html);
}

//登入页
Acan.login.show = function(){
	var title = 'Abans';
	if(Acan_app_cname) title=Acan_app_cname;
	var Ahtml = Acan.html();
	var html = Ahtml.tag('form',{onsubmit:'Acan.login.go();return false;',method:'post'},
		Ahtml.tag('p',{},'用户名： '+Ahtml.tag('input',{type:"text",name:"username"}))
		+Ahtml.tag('p',{},'密 &nbsp; 码： '+Ahtml.tag('input',{type:"password",name:"password"}))
		+Ahtml.tag('p',{},'验证码： '+Ahtml.tag('input',{type:"text",name:"authcode"}))
		+Ahtml.tag('p',{},Ahtml.tag('input',{type:"submit",name:"submit",value:'登入'}))
	);
	var obj=Object();
	obj.id='ajax_logins';
	obj["class"]='acan_win dis_none';
	obj.css={height:'150px'};
	obj._close={onclick:'Acan.login.close()','class':'_close'};//关闭按钮
	Acan.base.win(obj,title+' 登入',html);
	Acan.ajax_bg();
}
//登入页关闭
Acan.login.close = function(){
	jQuery("#ajax_logins").toggleClass('dis_none');
	Acan.ajax_bg(0);
}
//注册页
Acan.login.reg = function(){
	Acan.ajax_bg();
	var obj=Object();
	obj.id='ajax_logins';
	obj["class"]='acan_win dis_none';
	obj.css={height:'150px'};
	obj._close={onclick:'Acan.login.close()','class':'_close'};//关闭按钮
	jQuery.ajax({
		type: "POST",
		url: "index.php?a=index/reg",
		success: function(data){
			Acan.base.win(obj,'Abans 注册',decodeURI(data));
		}
	})
}
//注册提交
Acan.login.reg_go = function(){
	var params=jQuery('#ajax_logins input').serialize();
	jQuery.ajax({
		type: "POST",
		url: "index.php?a=index/reg_ajax",
		data: params,
		success: function(data){
			Acan.alert(decodeURI(data));
			setTimeout('Acan.url.refresh()',2000);
		}
	})
}
//登入成功提示
Acan.login.go = function(){
	var params=jQuery('#ajax_logins input').serialize();
	jQuery("#ajax_logins").hide();
	jQuery.ajax({
		type: "POST",
		url: "index.php?a=index/login_ajax",
		data: params,
		success: function(data){
			var obj = Acan.base.json_obj(data);
			Acan.alert(decodeURI(obj.msg));
			Acan.login.refresh(obj);
			setTimeout("Acan.alert();Acan.ajax_bg(0);",1000);
		}
	})
}
//退出页
Acan.login.logout = function(){
	jQuery.ajax({
		type: "GET",
		url: Aurl.App+"-login-out",
		success: function(data){
			if(data.status==1){
				Acan.alert(decodeURI(data.msg),1000);
				setTimeout('Acan.url.refresh()',1000);
			}
		}
	})
}

//sys登入页
Acan.login.sys = function(loginr){
	if(!loginr) loginr=1;
	var title = 'Abans',btn_back = '';
	var Ahtml = Acan.html();
	if(loginr!=1) btn_back = Ahtml.tag('input',{type:"button",onclick:"location.href='/"+Aurl.App+"'","class":"_btn",value:'首页'});
	var html = Ahtml.tag('form',{onsubmit:'Acan.login.sys_go('+loginr+');return false;',method:'post'},
		Ahtml.tag('p',{},'用户： '+Ahtml.tag('input',{type:"text",name:"name"}))
		+Ahtml.tag('p',{},'密码： '+Ahtml.tag('input',{type:"password",name:"pass"}))
		+Ahtml.tag('p',{},Ahtml.tag('input',{type:"submit","class":"_btn",value:'登入'})+btn_back)
	);
	html = Ahtml.tag('div',{"class":"-ajax_login"},html);
	var obj=Object();
	obj.id='ajax_logins';
	obj["class"]='acan_win dis_none';
	obj.css={height:'150px'};
	if(loginr==1) obj._close={onclick:'Acan.login.close()','class':'-close'};//关闭按钮
	if(Acan_app_cname){
		title = Acan_app_cname;
	}
	Acan.base.win(obj,title+' 登入',html);
	Acan.ajax_bg();
	jQuery("#ajax_logins input[name=\"name\"]").focus();
}
Acan.login.sys_go = function(loginr){
	var params=jQuery('#ajax_logins input').serialize();
	jQuery.ajax({
		type: "POST",
		url: "/"+Aurl.App+'-login',
		data: params,
		beforeSend: function(){Acan.alert('开始请求');},
		ajaxSend: function(){Acan.alert('发送请求');},
		success: function(data){
			var atime = 1000;
			if(loginr==2){atime = 1500;}
			if(typeof(data)=='object'){
				if(data.status==1){
					//jQuery("#ajax_logins").hide();
					setTimeout('Acan.url.refresh()',1000);
				}else{
					atime = 2000;
				}
				Acan.alert(decodeURI(data.msg),atime);
			}else if(loginr==1 || !loginr){setTimeout('Acan.url.refresh()',2000);}
		}
	})
	return false;
}
Acan.login.sys_auth = function(){
	jQuery.ajax({
		type: "POST",
		url: "/auth-login--do-auth",
		data: '',
		success: function(data){
			if(data != '1'){
				Acan.url.refresh();
			}
		}
	})
}


/*
var val;
for(var i in window){
	val += i+":"+window[i]+"\n";
	alert(i+":"+html[i])
}
*/
/*
网页可见区域宽： document.body.clientWidth
网页可见区域高： document.body.clientHeight
网页可见区域宽： document.body.offsetWidth (包括边线的宽)
网页可见区域高： document.body.offsetHeight (包括边线的高)
网页正文全文宽： document.body.scrollWidth
网页正文全文高： document.body.scrollHeight
网页被卷去的高： document.body.scrollTop
网页被卷去的左： document.body.scrollLeft
网页正文部分上： window.screenTop
网页正文部分左： window.screenLeft
屏幕分辨率的高： window.screen.height
屏幕分辨率的宽： window.screen.width
屏幕可用工作区高度： window.screen.availHeight
屏幕可用工作区宽度： window.screen.availWidth
*/


//ajax请求开始
//function ajax_status(){
//	jQuery("*").ajaxStart(function(){
//		jQuery("#ajax_msg").css({ width: 100, height: 100, left: (width/2)-100, });
//	});
//	//ajax请求发送
//	//jQuery("*").ajaxSend(function(evt, request, settings){
//	//	jQuery("#ajax_msg").html("开始请求: " + settings.url + "");
//	//});
//	//ajax请求完成
//	//jQuery("*").ajaxComplete(function(event,request, settings){
//	//	jQuery("#ajax_msg").html("请求完成");
//	//});
//	//ajax请求结束
//	jQuery("*").ajaxStop(function(){
//	//	jQuery("#dis_bg").html("");
//	});
//	//ajax请求错误
//	//jQuery("*").ajaxError(function(event,request, settings){
//	//});
//}



//ajax tpl msg 模型
function ajax(){}
ajax.tpl_msg = function(title,body,css){
	if(!css){
		var awidth = '300';
		var aheight = '100';
		var atop = "200"
	}else{
		var awidth = css['width'];
		var aheight = css['height'];
		var atop = css['top'];
	}
	jQuery("#ajax_tpl_msg").html("");//移除上次的
	jQuery("#ajax_tpl_msg").remove();//移除上次的
	jQuery(".-body").after('<div id="ajax_tpl_msg" class="ajax_tpl_msg"></div>');//添加空div
	var aleft = (document.body.clientWidth-awidth)/2;
	jQuery("#ajax_tpl_msg").css({"left":aleft,"width":awidth,"height":aheight,"top":atop});
	var html ='';
	html =ajax.tpl_msg_title(title);//标题
	html +=ajax.tpl_msg_body(body);//内容
	jQuery("#ajax_tpl_msg").html(html);
	jQuery("#ajax_tpl_msg").fadeIn(1000);
}
ajax.tpl_msg_title = function(str){
	var html;
	html  ='<div class="ajax_tpl_msg_title">';
	html +='<h2>'+str+'</h2>';
	html +='<span class="ajax_close" onclick="ajax_close(\'ajax_tpl_msg\')">&nbsp;</span>';
	html +='</div>';
	return html;
}
ajax.tpl_msg_body = function(str){
	return '<div id="ajax_tpl_msg_body" class="ajax_tpl_msg_body">'+str+'</div>';
}




//页面载入后执行
jQuery(document).ready(function(){
	setTimeout("Acan.login.refresh()",500);
	Acan.menu.ready('i');
	Acan.css.make();
});

